<template>
  <div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="18"
        ><span style="font-weight: blod"></span>参考资料</el-col
      >
      <el-col :span="1.5">
        <file-upload
          btnTxt="上传资料"
          :plain="true"
          :limit="200"
          :isShowTip="false"
          :value="fileValue"
          @setFile="setFile"
        />
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multipleSet"
          @click="handleDeleteSelect"
          >删除</el-button
        >
      </el-col>
    </el-row>
    <el-table
    :cell-style="{ padding: this.tablePadding }"
      :data="selectItems"
      border
      @selection-change="handleSelectionChangeSet"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="80" align="center" prop="fileUrl">
          <template slot-scope="scope">
            {{scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column
        label="文件地址"
        align="center"
        prop="fileName"
      >
      </el-table-column>
      <el-table-column label="操作" width="120" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row.repairTaskdetailId)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { removeByValue } from "@/utils/index";
import FileUpload from "@/components/FileUpload";
export default {
  props: ["selectItems"],
  components: { FileUpload },
  data() {
    return {
      multiple: true,
      multipleSet: true,
      open: false,
      ids: [],
      initId: 100000,
      fileValue:[]
    };
  },
  methods: {
       // 上传附件
    setFile(url, name) {
   
      this.fileValue=[]
    this.handleAdd(url,name)
    },
    handleAdd(url,name) {
      let obj = {
        fileUrl: url,
        fileName:name,
        referenceId: this.initId++,
      };
      this.selectItems.push(obj);
    },
    handleDelete(id) {
      removeByValue(this.selectItems, "referenceId", id);
    },
    handleDeleteSelect() {
      this.ids.forEach((item) => {
        removeByValue(this.selectItems, "referenceId", item);
      });
    },
    cancel() {
      this.open = false;
      this.selectItems = [];
    },
    handleSelectionChangeSet(selection) {
      this.ids = selection.map((item) => item.referenceId);

      this.multipleSet = !selection.length;
    },
  },
};
</script>

<style>
</style>